
<div class="wrap">
<h2>Event Management Options</h2>
<?php

if ( isset($_POST['Submit']) ) {
	update_option('em_register_page', $_POST['em_register_page']);
	update_option('em_use_ssl', $_POST['em_use_ssl']);
	//update_option('em_manager_role', $_POST['em_manager_role']);

	$roles = array();
	foreach($wp_roles->role_names as $role => $name) {
		if ($_POST[$role]) {
			array_push($roles, $role);
		}
	}
	update_option('em_manager_role', implode(":", $roles));

	if (get_option('em_register_uri')) {
		delete_option('em_register_uri');
	}
}

$pages = $wpdb->get_results("select id, post_title from $wpdb->posts where post_type = 'page'");

require_once(ABSPATH . "wp-content/plugins/EventManager/includes/upgrade.php");
?>
<form action="" method="post" id="em_options">
<table class="editform optiontable">
<tr valign="top">
	<th width="33%" scope="row">Registration Page:</th>
	<td>
		<select name="em_register_page">
			<?php foreach ($pages as $page) { ?>
			<option value="<?php echo $page->id ?>"<?php echo $page->id == get_option('em_register_page') ? ' selected="selected"' : "" ?>><?php echo $page->post_title ?></option>
			<?php } ?>
		</select>
	</td>
</tr>
<tr valign="top">
	<th width="33%" scope="row">Use SSL:</th>
	<td>
		<input name="em_use_ssl" type="checkbox" id="em_use_ssl" value="1" <?php checked('1', get_settings('em_use_ssl')); ?> />
	</td>
</tr>

<tr valign="top">
	<th width="33%" scope="row">Administrator Role:</th>
	<td>
<?php
$roles = explode(":", get_option('em_manager_role'));

foreach($wp_roles->role_names as $role => $name) {
	$checked = in_array($role, $roles) ? ' checked="checked"' : "";
	echo '<label style="display: block;">' . '<input type="checkbox" name="' . $role . '" value="' . $role . '"' . $checked . '> ' . $name . '</label>';
}
?>
	</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Update') ?> " />
</p>
</form>
</div>